package com.tjp.eight.views;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Point;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.TextView;

import com.tjp.eight.R;
import com.tjp.eight.utils.StringUtils;

/**
 * Created by Administrator on 2017/3/6.
 */

public class LogoutDailog extends Dialog {
    private TextView tv_title;
    private TextView tv_cancel;
    private TextView tv_logout;

    public LogoutDailog(Context context) {
        super(context, R.style.Dialog);

        View view = LayoutInflater.from(context).inflate(R.layout.dialog_logout, null);
        tv_cancel = (TextView) view.findViewById(R.id.tv_cancel);
        tv_title = (TextView) view.findViewById(R.id.tv_title);
        tv_logout = (TextView) view.findViewById(R.id.tv_logout);
        tv_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        tv_logout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (logoutInterface != null) {
                    logoutInterface.logout();
                }
            }
        });

        setContentView(view);
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        Display display = getWindow().getWindowManager().getDefaultDisplay();
        Point point = new Point();
        display.getSize(point);

        layoutParams.width = point.x;
        layoutParams.gravity = Gravity.CENTER;
        layoutParams.alpha = 1.0f;
        getWindow().setAttributes(layoutParams);


        setCanceledOnTouchOutside(true);
    }

    private LogoutInterface logoutInterface;

    public void setLogoutInterface(LogoutInterface logoutInterface) {
        this.logoutInterface = logoutInterface;
    }

    public interface LogoutInterface {
        void logout();
    }

    public void setTextTitle(String title) {
        if (StringUtils.isNullOrEmpty(title)) return;
        tv_title.setText("" + title);
    }

    public void setCancelText(String text) {
        tv_cancel.setText(text);
    }

    public void setOkText(String text) {
        tv_logout.setText(text);
    }
}
